package com.hfh.homework;

import org.junit.Test;

import java.io.*;

/**
 * @Author hfh
 * @Date 2022 09 07 14 20
 **/
public class Work5 {
    public static int count = 0;
    public static void main(String[] args) {

        File file = new File("D:\\JavaProject");
        copy(file);
        System.out.println("java文件的代码行数:"+count);
    }

    public  static void copy(File file){
        File[] arr = file.listFiles();
        for (File f: arr){
            if(f.isDirectory()){
                copy(f);
            }else {

                if (f.getName().length()>=5&&f.getName().endsWith(".java")){
                    System.out.println(f.getName());
                    try(BufferedReader br = new BufferedReader(new FileReader(f))) {
                    String str;
                    while ((str=br.readLine())!=null){
                        count++;
                    }
                    }catch (IOException e) {
                        e.printStackTrace();
                    }
                }

            }
        }
    }
}
